package com.googlecode.tidej.client.tree;

import java.util.Collection;

import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.googlecode.tidej.shared.model.Operation;

public class ModelCell extends AbstractCell<Object> {

  @Override
  public void render(com.google.gwt.cell.client.Cell.Context context,
      Object value, SafeHtmlBuilder sb) {
    if (value instanceof Collection) {
      sb.appendEscaped("Libraries");
    } else {
      try {
        if ((value instanceof Operation) && (((Operation) value).getOwner().getName().startsWith("Meta<")
             || ((Operation) value).getOwner().getName().startsWith("("))) {
          sb.appendHtmlConstant("<i>");
          sb.appendEscaped(value.toString());
          sb.appendHtmlConstant("</i>");
        } else {
          sb.appendEscaped(value.toString());
        }
      } catch(Exception e) {
        sb.appendEscaped("" + e.getMessage());
      }
    }
  }

}
